 /**
  * Created by ex-luandebiao001 on 2015/2/11.
 */
;
(function(){
    'use strict';
    
    var app = angular.module('fwa.mainApp');
    app.controller('performanceDataCtrl',['$scope','$state','$stateParams','$http','Modal','BaseURL',function($scope,$state,$stateParams,$http,Modal,baseURL){
       //URL参数
        $scope.UrlParams = $stateParams;
        var kpiTime = $scope.UrlParams.kpiTime;
        var grade = $scope.UrlParams.grade;
        var hospitalName = $scope.UrlParams.hospitalName;
        var hospitalCode = $scope.UrlParams.hospitalCode;
        var regionCode = $scope.UrlParams.regionCode;
      //医院信息
        $scope.hospital={name:hospitalName};
        
      //总得分信息查询 
        $http({
            method: 'GET',
            cache: false,
            url: baseURL + 'performance/score.do',
            params: {
                regionCode : regionCode,
                kpiTime : kpiTime,
                providerCode : hospitalCode,
                grade : grade
            }
        }).success(function(response) {
            $scope.tableScore = response;
            console.log(response);
          
        });
        
      //指标信息查询
        $scope.windowsList=[];
            $http({
                method: 'GET',
                cache: false,
                url: baseURL + 'performance/list.do',
                params: {
                    regionCode : regionCode,
                    kpiTime : kpiTime,
                    providerCode : hospitalCode,
                    grade : grade
                }
            }).success(function(response) {
                $scope.tableData = response;
                console.log(response);
                 
              //指标展示
                angular.forEach($scope.tableData,function(item,key){
                     $scope.windowsList.push(item);
                 });
            });
     
         //指标保存
            $scope.$watch('tableData',function(newValue,oldValue){
                $scope.newTableData =newValue;
            },true);
            
            $scope.save = function(){
                
                var data = angular.toJson($scope.newTableData);
                
                $http.post(baseURL + 'performance/insert.do', data).success(function(resp){
                    Modal.alert(resp.msg);
                }).error(function(data) {
                    Modal.alert('保存失败');
                });
            } 
            
        //取消按钮
            $scope.cancel=function(){
                $state.go('performanceRanking',{
                    type:0
                });
            };
            
        //导出报告
            $scope.exportFile = function(){
                $http({
                    method: 'GET',
                    cache: false,
                    url: baseURL + 'performance/exportFile.do',
                    params: {
                        kpiTime : kpiTime,
                        providerCode : hospitalCode
                    }
                }).success(function(response) {
                    $scope.tableData = response;
                    });
            }
            
            
    }]);
})();